from PIL import Image
import os

# 图片路径
image_path = r'E:\BaiduNetdiskDownload\temp\H2\IMG_3121.JPG'
# 打开图片
image = Image.open(image_path)

# 向右旋转90度,expand参数让图片尺寸适应新的形状
rotated_image = image.rotate(7, expand=False)
# 保存旋转后的图片,可以给它一个新的文件名
save_path = os.path.join(os.path.dirname(image_path), '旋转7.jpg')
rotated_image.save(save_path)

# # 向左旋转90度
# rotated_image = image.rotate(19, expand=True)
# # 保存旋转后的图片
# save_path = os.path.join(os.path.dirname(image_path), '向左90.jpg')
# rotated_image.save(save_path)